In [1]:
import os, sys
sys.path.insert(0, os.path.abspath(".."))
In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import open_cp.geometry as geometry
import matplotlib.patches
In [3]:
points = np.asarray([[1,1], [3,2], [1,3], [2,4]])
voroni = geometry.Voroni(points)
In [4]:
voroni.points
Out[4]:
In [5]:
voroni.vertices
Out[5]:
In [6]:
fig, ax = plt.subplots(figsize=(8,8))
ax.scatter(voroni.points[:,0], voroni.points[:,1], color="blue")
for index, (x, y) in enumerate(voroni.points):
ax.text(x+0.02,y+0.02,index)
ax.scatter(voroni.vertices[:,0], voroni.vertices[:,1], marker="+", color="black")
for index, (x, y) in enumerate(voroni.vertices):
ax.text(x+0.02,y+0.02,index)
for poly in voroni.polygons(inf_dist=5):
p = matplotlib.patches.Polygon(poly, fc="red", ec="black", alpha=0.5)
ax.add_patch(p)
ax.set_aspect(1)
ax.set(xlim=[-5,8], ylim=[-3,7])
Out[6]:
In [7]:
voroni.polygon_for(0, inf_dist=5)
Out[7]:
In [8]:
voroni.regions
Out[8]:
In [9]:
voroni.ridge_vertices
Out[9]:
In [10]:
voroni.ridge_points
Out[10]:
In [11]:
voroni.point_region
Out[11]:
In [12]:
points = np.asarray([[1,1], [3,2], [1,3], [2,4], [4,4], [5,0]])
voroni = geometry.Voroni(points)
fig, ax = plt.subplots(figsize=(8,8))
ax.scatter(voroni.points[:,0], voroni.points[:,1], color="blue")
for index, (x, y) in enumerate(voroni.points):
ax.text(x+0.02,y+0.02,index)
ax.scatter(voroni.vertices[:,0], voroni.vertices[:,1], marker="+", color="black")
for index, (x, y) in enumerate(voroni.vertices):
ax.text(x+0.02,y+0.02,index)
for poly in voroni.polygons(inf_dist=5):
p = matplotlib.patches.Polygon(poly, fc="red", ec="black", alpha=0.5)
ax.add_patch(p)
ax.set_aspect(1)
ax.set(xlim=[-4,11], ylim=[-6,9])
Out[12]:
In [13]:
points = np.asarray([[0,0], [1,0], [0,1], [1,1]])
voroni = geometry.Voroni(points)
fig, ax = plt.subplots(figsize=(8,8))
ax.scatter(voroni.points[:,0], voroni.points[:,1], color="blue")
for index, (x, y) in enumerate(voroni.points):
ax.text(x+0.02,y+0.02,index)
ax.scatter(voroni.vertices[:,0], voroni.vertices[:,1], marker="+", color="black")
for index, (x, y) in enumerate(voroni.vertices):
ax.text(x+0.02,y+0.02,index)
for poly in voroni.polygons(inf_dist=5):
p = matplotlib.patches.Polygon(poly, fc="red", ec="black", alpha=0.5)
ax.add_patch(p)
ax.set_aspect(1)
ax.set(xlim=[-6,7], ylim=[-6,7])
Out[13]:
In [14]:
points = np.asarray([[1,1], [3,2], [1,3], [2,4], [4,4], [5,0]])
voroni = geometry.Voroni(points)
fig, ax = plt.subplots(figsize=(8,8))
ax.scatter(voroni.points[:,0], voroni.points[:,1], color="blue")
for index, (x, y) in enumerate(voroni.points):
ax.text(x+0.02,y+0.02,index)
ax.scatter(voroni.vertices[:,0], voroni.vertices[:,1], marker="+", color="black")
for index, (x, y) in enumerate(voroni.vertices):
ax.text(x+0.02,y+0.02,index)
for i in range(6):
poly = voroni.polygon_for_by_distance(i, 1)
p = matplotlib.patches.Polygon(poly, fc="red", ec="black", alpha=0.5)
ax.add_patch(p)
ax.set_aspect(1)
ax.set(xlim=[-4,11], ylim=[-6,9])
None
In [ ]: